/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.insurance.cis.views;

import com.insurance.cis.utils.CisConstants;
import com.insurance.cis.utils.HtmlReportUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author TruongLQ
 */
public class HelpUserGuideJPanelView extends javax.swing.JPanel {

    private MainJFrameView mainJpnl;
    private File helpFile;
    /**
     * Creates new form HelpUserGuideJPanelView
     */
    public HelpUserGuideJPanelView(javax.swing.JFrame jFrame, File file) {
        initComponents();
        mainJpnl = (MainJFrameView) jFrame;
        helpFile = file;
        loadContents();
    }

    private void loadContents() {
        if(helpFile != null) {
            BufferedReader br = null;
            try {
                br = new BufferedReader(new FileReader(helpFile));
                String lineStr;
                StringBuilder contents = new StringBuilder("");
                while ((lineStr = br.readLine())!=null) {
                    contents.append(lineStr);
                }
                br.close();
                contentsEditor.setContentType("text/html");
                String fullContentsImageReplacement 
                        = HtmlReportUtils.replaceImageLocation(
                        helpFile,contents, CisConstants.USER_GUIDE_HTML);
                contentsEditor.setText(fullContentsImageReplacement);
            } catch (IOException ex) {
                Logger.getLogger(HelpUserGuideJPanelView.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    if (br != null) {
                        br.close();
                    }
                } catch (IOException ex) {
                    Logger.getLogger(HelpUserGuideJPanelView.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        contentsEditor = new javax.swing.JEditorPane();

        contentsEditor.setEditable(false);
        jScrollPane2.setViewportView(contentsEditor);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JEditorPane contentsEditor;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables
}
